<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="inputValue" @keyup.enter="add">
        <ul>
            <li v-for="(item,index) in arr">
                {{ index+1 }}{{ item }}
                <span @click="remove(index)">x</span>
            </li>
        </ul>
        <span v-if="arr.length!=0">{{ arr.length }}</span>
        <span @click="clear" v-show="arr.length!=0">clear</span>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                arr: ["你好", "世界", "李明"],
                inputValue: "好好学习"
            },
            methods: {
                add: function () {
                    this.arr.push(this.inputValue);
                },
                remove: function (index) {
                    this.arr.splice(index, 1);
                },
                clear: function () {
                    this.arr = [];
                }
            }
        })
    </script>
</body>

</html>